<?php
class BaseController {

    public function getInput($http_method) {
        switch(strtolower($http_method)) {
            case 'get' :
                return $_GET;
                break;
            case 'post' :
                return $_POST;
                break;
            case 'put' :
            case 'delete' :
                parse_str(file_get_contents('php://input'), $input);
                return $input;
                break;
        }
    }
    
    private static function getTplPath($tpl) {
        $tpl_dir = ConfigParserLib::get('tpl','dir');
        return $tpl_dir . $tpl . '.tpl';
    }

    public static function output($mix) {
        if(isset($mix['jump']) && $mix['jump'] === true) {
            $uri = isset($mix['params']) && !empty($mix['params']) ? $mix['uri'] . '?' . http_build_query($mix['params']) : $mix['uri'];
            header('Location: ' . $uri, true, $mix['code']);
            return true;
        }
        $tpl_path = self::getTplPath($mix['tpl']);
        if(isset($mix['data'])) {
            $v = $mix['data'];
        }
        header('Content-Type: text/html; charset=utf-8');
        require $tpl_path;
        return true;
    }
}
?>
